using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using THSERP.BusinessEntities;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using THSLib;using THSERP.BaseProvider;

namespace THSERP.Modules.POS
{
    public partial class guiIssueGiftVoucher : THSERPScreen
    {
        public guiIssueGiftVoucher()
        {
            InitializeComponent();
        }

        private void guiIssueGiftVoucher_Load(object sender, EventArgs e)
        {
            //Get valid date from ADConfigValues
            ADConfigValuesController objConfigValuesController = new ADConfigValuesController();
            ADConfigValuesInfo objConfigValuesInfo = (ADConfigValuesInfo)objConfigValuesController.GetObjectByConfigKey(CreditNote.CreditNoteModule.cstCreditNoteConfigValidDays);
            fld_dteExpiringDate.EditValue = DateTime.Now.AddDays(Convert.ToInt32(objConfigValuesInfo.ADConfigKeyValue));
            fld_txtAmount.Text = "0";
        }

        private void fld_btnOK_Click(object sender, EventArgs e)
        {
            if (Convert.ToDouble(fld_txtAmount.Text) == 0)
            {
                MessageBox.Show("Please enter the gift voucher's amount.", "#Message#", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            POSEntities entity = (POSEntities)((BaseModuleERP)Module).CurrentModuleEntity;
            entity.ARCreditNotesObject = new ARCreditNotesInfo();
            if (!String.IsNullOrEmpty(fld_txtNumber.Text.Trim()))
                entity.ARCreditNotesObject.ARCreditNoteNo = fld_txtNumber.Text;
            entity.ARCreditNotesObject.ARCreditNoteTotalAmount = Convert.ToDouble(fld_txtAmount.Text);
            entity.ARCreditNotesObject.ARCreditNoteValidateDate = fld_dteExpiringDate.DateTime;
            entity.ARCreditNotesObject.ARCreditNoteRemainingAmount = entity.ARCreditNotesObject.ARCreditNoteTotalAmount;
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void fld_btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }

        private void guiIssueGiftVoucher_FormClosed(object sender, FormClosedEventArgs e)
        {
            if (this.DialogResult == DialogResult.Cancel)
                ((BaseModuleERP)Module).ActionCancel();
        }
    }
}